package m202405.d13;

import java.util.ArrayList;
import java.util.List;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/13 15:35
 */
public class Q98 {
    public boolean isValidBST(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        travel(root, list);
        int last = list.get(0);
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i) < last) {
                return false;
            }
            last = list.get(i);
        }
        return true;
    }

    private void travel(TreeNode node, List<Integer> list) {
        if (node == null) {
            return;
        }
        travel(node.left, list);
        list.add(node.val);
        travel(node.right, list);
    }
}
